package experimentReport;

import java.util.HashMap;

public class UserStorage {
    private static UserStorage instance = new UserStorage();
    private HashMap<String, User> users = new HashMap<>();

    private UserStorage() {
        // 私有构造函数，防止外部实例化
    }

    public static UserStorage getInstance() {
        return instance;
    }

    public boolean addUser(User user) {
        if (users.containsKey(user.getUserID())) {
            return false; // 用户ID已存在，注册失败
        }
        users.put(user.getUserID(), user);
        return true; // 注册成功
    }

    public User getUserByID(String userID) {
        return users.get(userID); // 根据用户ID获取用户信息
    }

    public boolean checkUserCredentials(String userID, String password) {
        if (users.containsKey(userID)) {
            User user = users.get(userID);
            return user.getPassword().equals(password); // 验证用户ID和密码是否匹配
        }
        return false; // 用户ID不存在
    }
}
